package com.platform.modules.app.controller;

import com.alibaba.fastjson.JSONObject;
import com.platform.annotation.IgnoreAuth;
import com.platform.common.utils.Constant;
import com.platform.common.utils.JedisUtil;
import com.platform.common.utils.RestResponse;
import com.platform.modules.platform.entity.PlatformColumnEntity;
import com.platform.modules.platform.service.PlatformColumnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/app/column")
@Api(tags = "AppColumnController|栏目表")
public class AppColumnController {

    @Autowired
    PlatformColumnService columnService;
    @Autowired
    JedisUtil jedisUtil;

    /**
     * 获取卡卷列表
     */
    @IgnoreAuth
    @GetMapping("getColumn")
    @ApiOperation(value = "获取栏目数据", notes = "获取栏目数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型，0 首页底部栏，1个人中心", example = "", dataType = "int")
    })
    public RestResponse getColumn(@RequestParam(defaultValue = "0") Integer type) {
        if (jedisUtil.exists(Constant.COLUMN + type)) {
            return RestResponse.success().put("data", JSONObject.parse(jedisUtil.get(Constant.COLUMN + type)));
        }

        List<PlatformColumnEntity> columnEntities=columnService.getList(type);

        return RestResponse.success().put("data", columnEntities);
    }
}
